/*
 * @Descripttion: 接口响应验证
 * @Author: MajorMayer
 * @Date: 2020-10-13 16:28:51
 * @LastEditors: MajorMayer
 * @LastEditTime: 2021-07-27 14:35:18
 */
import isNull from 'lodash/isNull'

//验证接口结果
export function checkResponse(err, response, needWarnning = true) {
    if (err) {
        if (err.message != 'isCancel') {
            needWarnning && alert(err.message)
        }
        return [false, , , , err.message]
    }

    if (isNull(response)) return [false, , , , '无响应']

    var { msgCode, msg, data, Data = null, totalCount } = response
    if (msgCode == '9999') {
        needWarnning && alert(msg)
        return [false, , , msgCode, msg]
    }
    if (msgCode == '0001') {
        needWarnning && alert(msg)
        return [false, , , msgCode, msg]
    }

    return [true, data ?? Data, totalCount, msgCode, msg]
}